package org.jssvc.opac.data

import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import org.jssvc.opac.bean.BookStore

object JsoupUtils {

    // 解析库存
    fun parseBookStoreInfo(html: String):List<BookStore>{
        if(html=="") return emptyList()

        val list = arrayListOf<BookStore>()

        var doc = Jsoup.parseBodyFragment(html) as Document
        var body = doc.body() as Element
        var trs = body.getElementsByTag("tr") as Elements

        trs.forEach {
            var tds = it.getElementsByTag("td") as Elements
            var bean = BookStore()
            bean.callNo = tds[0].text()
            bean.barCode = tds[1].text()
            bean.pubYear = tds[2].text()
            bean.place = tds[3].text()
            bean.state = tds[4].text()
            list.add(bean)
        }

        if (list.size != 0) {
            list.removeAt(0)
        }
        return list
    }
}